package com.cloudlinkscm.base.filecenter.dao;

import com.cloudlinkscm.base.filecenter.mapper.SysAuthCodeMapper;
import com.cloudlinkscm.base.filecenter.model.SysAuthCode;
import com.cloudlinkscm.loms.framework.core.exception.InvalidArgumentException;
import com.cloudlinkscm.loms.framework.dao.GenericDao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.Collection;
import java.util.List;

/**
 * Created by syq on 2017/7/22.
 */
@Repository
public class SysAuthCodeDao extends GenericDao<SysAuthCode,String> {
    private SysAuthCodeMapper sysAuthCodeMapper;
    @Autowired
    public SysAuthCodeDao(SysAuthCodeMapper mapper) {
        super(mapper);
        this.sysAuthCodeMapper = mapper;
    }

    /**
     * 获取指定系统编码对应的系统授权信息
     * @param sysCode
     * @return
     */
    public SysAuthCode getBySysCode(String sysCode){
        if(StringUtils.isBlank(sysCode)){
            throw new InvalidArgumentException("sysCode");
        }
        SysAuthCode query = new SysAuthCode();
        query.setSysCode(sysCode);
        //todo:: 按过期时间过滤
        SysAuthCode code = selectOne(query);
        return  code;
    }

    /**
     * 批量获取指定系统编码对应的系统授权信息
     * @param sysCodes
     * @return
     */
    public List<SysAuthCode> getBySysCode(Collection<String> sysCodes){
        if(CollectionUtils.isEmpty(sysCodes)){
            return null;
        }
        Example example = new Example(SysAuthCode.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andIn("sysCode",sysCodes);
        return selectByExample(example);
    }

}
